package net.myspring.middle.domain;

import com.google.common.collect.Sets;
import net.myspring.common.domain.DataEntity;
import net.myspring.common.mybatis.provider.annotation.Entity;
import net.myspring.common.mybatis.provider.annotation.Table;
import net.myspring.common.utils.Collections3;
import net.myspring.common.utils.Const;
import net.myspring.common.utils.StringUtils;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Entity
@Table(name="sys_account")
public class Account extends DataEntity<Account> {
    private String loginName;
    private String password;
    private String outId;
    private String outPassword;

    private Set<Role> roleSet = Sets.newLinkedHashSet();
    private Department department;
    private String departmentId;

    private List<Menu> menus;
    private List<String> roleIds;

    private String companies;

    public List<String> getRoleIds() {
        if (roleIds == null && Collections3.isNotEmpty(roleSet)) {
            roleIds = Collections3.extractToList(roleSet, "id");
        }
        return roleIds;
    }

    public void setRoleIds(List<String> roleIds) {
        this.roleIds = roleIds;
    }

    public String getDepartmentId() {
        if (departmentId == null && department != null) {
            departmentId = department.getId();
        }
        return departmentId;
    }

    public void setDepartmentId(String departmentId) {
        this.departmentId = departmentId;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getOutId() {
        return outId;
    }

    public void setOutId(String outId) {
        this.outId = outId;
    }

    public String getOutPassword() {
        return outPassword;
    }

    public void setOutPassword(String outPassword) {
        this.outPassword = outPassword;
    }

    public Set<Role> getRoleSet() {
        return roleSet;
    }

    public void setRoleSet(Set<Role> roleSet) {
        this.roleSet = roleSet;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public List<Menu> getMenus() {
        return menus;
    }

    public void setMenus(List<Menu> menus) {
        this.menus = menus;
    }

    public String getCompanies() {
        return companies;
    }

    public void setCompanies(String companies) {
        this.companies = companies;
    }

    public List<String> getCloudList() {
        List<String> cloudList = StringUtils.getSplitList(companies, Const.CharEnum.COMMA.getValue());
        return cloudList;
    }

}